home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / DHTML - Calenders / basic-calendar.izs next >
Text File  |  2005-08-31  |  13KB  |  402 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Basic calendar
  4.  
  5. <!/TITLE>
  6.  
  7. <!BROWSER>FF1+ IE5+ Opr7<!/BROWSER>
  8.  
  9. <!DESCRIPTION>If you need a simple, elegant calendar to display the current days of the month, Basic Calendar is an excellent script for the purpose. Uses CSS to allow easy changing to its appearance, everything from calendar dimensions, colors, down to the font used to highlight the current day.
  10.  
  11. <!/DESCRIPTION> 
  12.  
  13. <!CATEGORY>calenders<!/CATEGORY>
  14.  
  15. <!SCRIPT>
  16. <!-- START OF SCRIPT -->
  17. <!-- Step 1: Insert the below into the <HEAD> section of your page: -->
  18. <style type="text/css">
  19.  
  20. .main {
  21. width:200px;
  22. border:1px solid black;
  23. }
  24.  
  25. .month {
  26. background-color:black;
  27. font:bold 12px verdana;
  28. color:white;
  29. }
  30.  
  31. .daysofweek {
  32. background-color:gray;
  33. font:bold 12px verdana;
  34. color:white;
  35. }
  36.  
  37. .days {
  38. font-size: 12px;
  39. font-family:verdana;
  40. color:black;
  41. background-color: lightyellow;
  42. padding: 2px;
  43. }
  44.  
  45. .days #today{
  46. font-weight: bold;
  47. color: red;
  48. }
  49.  
  50. </style>
  51.  
  52.  
  53. <script type="text/javascript" src="basiccalendar.js">
  54.  
  55. /***********************************************
  56. * Basic Calendar-By Brian Gosselin at http://scriptasylum.com/bgaudiodr/
  57. * Script featured on Dynamic Drive (http://www.dynamicdrive.com)
  58. * This notice must stay intact for use
  59. * Visit http://www.dynamicdrive.com/ for full source code
  60. ***********************************************/
  61.  
  62. </script> 
  63. <!-- The above references an external .js file. Download basiccalendar.js (by right clicking, and selecting "Save As"), and upload to your webpage directory.
  64.  
  65. Within the above code, you may customize the CSS rules to change all visual aspects of the calendar.
  66.  
  67. Step 2: Finally, insert the below script where you wish the calendar to appear on your page:
  68.  
  69. -->
  70. <script type="text/javascript">
  71.  
  72. var todaydate=new Date()
  73. var curmonth=todaydate.getMonth()+1 //get current month (1-12)
  74. var curyear=todaydate.getFullYear() //get current year
  75.  
  76. document.write(buildCal(curmonth ,curyear, "main", "month", "daysofweek", "days", 1));
  77. </script>
  78. <!-- Additional Information
  79. Basic Calendar uses one key function, buildCal(), to display a calendar. This function looks like this:
  80.  
  81. buildCal(4, 2003, "main", "month", "daysofweek", "days", 0)Here's an explanation of all of its parameters:
  82.  
  83. 4 The month you wish to display, where 1=January, and 12=December. 
  84. 2003 The year you wish to display. 
  85. main Name of the CSS class to style the calendar's outermost table.  
  86. month Name of the CSS class to style the calendar's month/year bar.  
  87. daysofweek Name of the CSS class to style the calendar's week days row  
  88. days Name of the CSS class to style the individual days cells.  
  89. 0 The thickness of the border between all cells. 0=no border. 
  90.  
  91. buildCal() simply returns the entire calendar in string format, so in order to display it, you'll need to invoke document.write(), as shown in the code of Step 2: 
  92.  
  93. document.write(buildCal(4, 2003, "main", "month", "daysofweek", "days", 0))Such a design of Basic Calendar means you can easily invoke it many times on the page, and in a variety of ways.
  94.  
  95. -Displaying multiple calendar months
  96. The below example displays the calendar for the previous, current, and future month. It should replace the code of Step 2:
  97.  
  98. <script type="text/javascript">
  99.  
  100. var todaydate=new Date()
  101. var curmonth=todaydate.getMonth()+1 //get current month (1-12)
  102. var curyear=todaydate.getFullYear() //get current year
  103.  
  104. </script>
  105.  
  106. <table border="0" cellspacing="0" cellpadding="3">
  107. <tr>
  108. <td width="33%">
  109. <script>
  110. document.write(buildCal(curmonth-1 ,curyear, "main", "month", "daysofweek", "days", 1));
  111. </script></td>
  112. <td width="33%">
  113. <script>
  114. document.write(buildCal(curmonth ,curyear, "main", "month", "daysofweek", "days", 1));
  115. </script></td>
  116. <td width="34%">
  117. <script>
  118. document.write(buildCal(curmonth+1 ,curyear, "main", "month", "daysofweek", "days", 1));
  119. </script></td>
  120. </tr>
  121. </table> 
  122.  
  123. July - 2005 
  124. S M T W T F S 
  125.           1 2 
  126. 3 4 5 6 7 8 9 
  127. 10 11 12 13 14 15 16 
  128. 17 18 19 20 21 22 23 
  129. 24 25 26 27 28 29 30 
  130. 31             
  131.  August - 2005 
  132. S M T W T F S 
  133.   1 2 3 4 5 6 
  134. 7 8 9 10 11 12 13 
  135. 14 15 16 17 18 19 20 
  136. 21 22 23 24 25 26 27 
  137. 28 29 30 31       
  138.               
  139.  September - 2005 
  140. S M T W T F S 
  141.         1 2 3 
  142. 4 5 6 7 8 9 10 
  143. 11 12 13 14 15 16 17 
  144. 18 19 20 21 22 23 24 
  145. 25 26 27 28 29 30   
  146.               
  147.  
  148.  
  149.  
  150. As you can see, buildCal() is invoked three times here within table cells to display it three times on the page. 
  151.  
  152. -Displaying an entire year dynamically
  153. To demonstrate how versatile this script is, you can create simple functions to display the calendar dynamically, such as on demand using a drop down menu. The below code should replace the code of Step 2:
  154.  
  155. <form>
  156. <select onChange="updatecalendar(this.options)">
  157. <script type="text/javascript">
  158.  
  159. var themonths=['January','February','March','April','May','June',
  160. 'July','August','September','October','November','December']
  161.  
  162. var todaydate=new Date()
  163. var curmonth=todaydate.getMonth()+1 //get current month (1-12)
  164. var curyear=todaydate.getFullYear() //get current year
  165.  
  166. function updatecalendar(theselection){
  167. var themonth=parseInt(theselection[theselection.selectedIndex].value)+1
  168. var calendarstr=buildCal(themonth, curyear, "main", "month", "daysofweek", "days", 0)
  169. if (document.getElementById)
  170. document.getElementById("calendarspace").innerHTML=calendarstr
  171. }
  172.  
  173. document.write('<option value="'+(curmonth-1)+'" selected="yes">Current Month</option>')
  174. for (i=0; i<12; i++) //display option for 12 months of the year
  175. document.write('<option value="'+i+'">'+themonths[i]+' '+curyear+'</option>')
  176.  
  177.  
  178. </script>
  179. </select>
  180.  
  181. <div id="calendarspace">
  182. <script>
  183. //write out current month's calendar to start
  184. document.write(buildCal(curmonth, curyear, "main", "month", "daysofweek", "days", 0))
  185. </script>
  186. </div>
  187.  
  188. </form>
  189.  
  190.  Current MonthJanuary 2005February 2005March 2005April 2005May 2005June 2005July 2005August 2005September 2005October 2005November 2005December 2005 
  191.  
  192. August - 2005 
  193. S M T W T F S 
  194.   1 2 3 4 5 6 
  195. 7 8 9 10 11 12 13 
  196. 14 15 16 17 18 19 20 
  197. 21 22 23 24 25 26 27 
  198. 28 29 30 31       
  199.               
  200.  
  201. Here we dynamically invoke buildCal() with different month parameters per the selected form option, and instead of using document.write() to output the result, assign it to the .innerHTML property of DHTML to dynamically display it instead.
  202.  
  203. Not bad for a "basic" calendar eh?
  204. -->
  205. <!-- END OF SCRIPT -->
  206. <!/SCRIPT>
  207.  
  208. <!PREVIEW>
  209. <!-- START OF SCRIPT -->
  210.  
  211. <!-- Step 1: Insert the below into the <HEAD> section of your page: -->
  212. <style type="text/css">
  213.  
  214. .main {
  215. width:200px;
  216. border:1px solid black;
  217. }
  218.  
  219. .month {
  220. background-color:black;
  221. font:bold 12px verdana;
  222. color:white;
  223. }
  224.  
  225. .daysofweek {
  226. background-color:gray;
  227. font:bold 12px verdana;
  228. color:white;
  229. }
  230.  
  231. .days {
  232. font-size: 12px;
  233. font-family:verdana;
  234. color:black;
  235. background-color: lightyellow;
  236. padding: 2px;
  237. }
  238.  
  239. .days #today{
  240. font-weight: bold;
  241. color: red;
  242. }
  243.  
  244. </style>
  245.  
  246.  
  247. <script type="text/javascript" src="basiccalendar.js">
  248.  
  249. /***********************************************
  250. * Basic Calendar-By Brian Gosselin at http://scriptasylum.com/bgaudiodr/
  251. * Script featured on Dynamic Drive (http://www.dynamicdrive.com)
  252. * This notice must stay intact for use
  253. * Visit http://www.dynamicdrive.com/ for full source code
  254. ***********************************************/
  255.  
  256. </script> 
  257. <!-- The above references an external .js file. Download basiccalendar.js (by right clicking, and selecting "Save As"), and upload to your webpage directory.
  258.  
  259. Within the above code, you may customize the CSS rules to change all visual aspects of the calendar.
  260.  
  261. Step 2: Finally, insert the below script where you wish the calendar to appear on your page:
  262.  
  263. -->
  264. <script type="text/javascript">
  265.  
  266. var todaydate=new Date()
  267. var curmonth=todaydate.getMonth()+1 //get current month (1-12)
  268. var curyear=todaydate.getFullYear() //get current year
  269.  
  270. document.write(buildCal(curmonth ,curyear, "main", "month", "daysofweek", "days", 1));
  271. </script>
  272. <!-- Additional Information
  273. Basic Calendar uses one key function, buildCal(), to display a calendar. This function looks like this:
  274.  
  275. buildCal(4, 2003, "main", "month", "daysofweek", "days", 0)Here's an explanation of all of its parameters:
  276.  
  277. 4 The month you wish to display, where 1=January, and 12=December. 
  278. 2003 The year you wish to display. 
  279. main Name of the CSS class to style the calendar's outermost table.  
  280. month Name of the CSS class to style the calendar's month/year bar.  
  281. daysofweek Name of the CSS class to style the calendar's week days row  
  282. days Name of the CSS class to style the individual days cells.  
  283. 0 The thickness of the border between all cells. 0=no border. 
  284.  
  285. buildCal() simply returns the entire calendar in string format, so in order to display it, you'll need to invoke document.write(), as shown in the code of Step 2: 
  286.  
  287. document.write(buildCal(4, 2003, "main", "month", "daysofweek", "days", 0))Such a design of Basic Calendar means you can easily invoke it many times on the page, and in a variety of ways.
  288.  
  289. -Displaying multiple calendar months
  290. The below example displays the calendar for the previous, current, and future month. It should replace the code of Step 2:
  291.  
  292. <script type="text/javascript">
  293.  
  294. var todaydate=new Date()
  295. var curmonth=todaydate.getMonth()+1 //get current month (1-12)
  296. var curyear=todaydate.getFullYear() //get current year
  297.  
  298. </script>
  299.  
  300. <table border="0" cellspacing="0" cellpadding="3">
  301. <tr>
  302. <td width="33%">
  303. <script>
  304. document.write(buildCal(curmonth-1 ,curyear, "main", "month", "daysofweek", "days", 1));
  305. </script></td>
  306. <td width="33%">
  307. <script>
  308. document.write(buildCal(curmonth ,curyear, "main", "month", "daysofweek", "days", 1));
  309. </script></td>
  310. <td width="34%">
  311. <script>
  312. document.write(buildCal(curmonth+1 ,curyear, "main", "month", "daysofweek", "days", 1));
  313. </script></td>
  314. </tr>
  315. </table> 
  316.  
  317. July - 2005 
  318. S M T W T F S 
  319.           1 2 
  320. 3 4 5 6 7 8 9 
  321. 10 11 12 13 14 15 16 
  322. 17 18 19 20 21 22 23 
  323. 24 25 26 27 28 29 30 
  324. 31             
  325.  August - 2005 
  326. S M T W T F S 
  327.   1 2 3 4 5 6 
  328. 7 8 9 10 11 12 13 
  329. 14 15 16 17 18 19 20 
  330. 21 22 23 24 25 26 27 
  331. 28 29 30 31       
  332.               
  333.  September - 2005 
  334. S M T W T F S 
  335.         1 2 3 
  336. 4 5 6 7 8 9 10 
  337. 11 12 13 14 15 16 17 
  338. 18 19 20 21 22 23 24 
  339. 25 26 27 28 29 30   
  340.               
  341.  
  342.  
  343.  
  344. As you can see, buildCal() is invoked three times here within table cells to display it three times on the page. 
  345.  
  346. -Displaying an entire year dynamically
  347. To demonstrate how versatile this script is, you can create simple functions to display the calendar dynamically, such as on demand using a drop down menu. The below code should replace the code of Step 2:
  348.  
  349. <form>
  350. <select onChange="updatecalendar(this.options)">
  351. <script type="text/javascript">
  352.  
  353. var themonths=['January','February','March','April','May','June',
  354. 'July','August','September','October','November','December']
  355.  
  356. var todaydate=new Date()
  357. var curmonth=todaydate.getMonth()+1 //get current month (1-12)
  358. var curyear=todaydate.getFullYear() //get current year
  359.  
  360. function updatecalendar(theselection){
  361. var themonth=parseInt(theselection[theselection.selectedIndex].value)+1
  362. var calendarstr=buildCal(themonth, curyear, "main", "month", "daysofweek", "days", 0)
  363. if (document.getElementById)
  364. document.getElementById("calendarspace").innerHTML=calendarstr
  365. }
  366.  
  367. document.write('<option value="'+(curmonth-1)+'" selected="yes">Current Month</option>')
  368. for (i=0; i<12; i++) //display option for 12 months of the year
  369. document.write('<option value="'+i+'">'+themonths[i]+' '+curyear+'</option>')
  370.  
  371.  
  372. </script>
  373. </select>
  374.  
  375. <div id="calendarspace">
  376. <script>
  377. //write out current month's calendar to start
  378. document.write(buildCal(curmonth, curyear, "main", "month", "daysofweek", "days", 0))
  379. </script>
  380. </div>
  381.  
  382. </form>
  383.  
  384.  Current MonthJanuary 2005February 2005March 2005April 2005May 2005June 2005July 2005August 2005September 2005October 2005November 2005December 2005 
  385.  
  386. August - 2005 
  387. S M T W T F S 
  388.   1 2 3 4 5 6 
  389. 7 8 9 10 11 12 13 
  390. 14 15 16 17 18 19 20 
  391. 21 22 23 24 25 26 27 
  392. 28 29 30 31       
  393.               
  394.  
  395. Here we dynamically invoke buildCal() with different month parameters per the selected form option, and instead of using document.write() to output the result, assign it to the .innerHTML property of DHTML to dynamically display it instead.
  396.  
  397. Not bad for a "basic" calendar eh?
  398. -->
  399. <!-- END OF SCRIPT -->
  400. <!/PREVIEW>
  401.  
  402. <!RELATED>NONE<!/RELATED>